package com.atu.poker.db;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * JDBC操作的工具类
 * 
 * @author ATU
 *
 */
public class JdbcUtils {

	/**
	 * 释放connection链接
	 * 
	 * @param connection
	 */
	public static void releaceConnection(Connection connection) {
		if(connection != null){
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	private static DataSource dataSource = null;

	static {
		//使用c3p0连接池，连接oracle数据库使用oracle驱动应该为ojdbc14.jar，使用classes12.jar会报错
		//F:\app\ATU\product\11.2.0\dbhome_1\owb\wf\lib 为ojdbc14.jar路径
		dataSource = new ComboPooledDataSource("poker");
	}

	/**
	 * 返回数据源的一个connection对象
	 * 
	 * @return
	 * @throws SQLException 
	 * @throws Exception
	 */
	public static Connection getConnection() throws SQLException {

		return dataSource.getConnection();
	}
}
